package com.woniu.backstage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.backstage.dao.TbOrderMapper;
import com.woniu.backstage.entity.TbOrder;
import com.woniu.backstage.entity.form.OrderForm;
import com.woniu.backstage.service.ITbOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;

/**
 * <p>
 * 订单表 服务实现类
 * </p>
 *
 * @author spirit
 * @since 2020-04-18
 */
@Service
public class TbOrderServiceImpl extends ServiceImpl<TbOrderMapper, TbOrder> implements ITbOrderService {

    @Autowired
    private TbOrderMapper orderMapper;

    @Override
    public IPage<TbOrder> pageLimit(Page<TbOrder> page, OrderForm orderForm) {
        QueryWrapper<TbOrder> wrapper = new QueryWrapper<>();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if(orderForm.getOutTradeNo() != null && orderForm.getOutTradeNo().length() > 0){
            wrapper.eq("out_trade_no",orderForm.getOutTradeNo());
        }
        if(orderForm.getProductType() != null){
            wrapper.eq("product_type",orderForm.getProductType());
        }
        if(orderForm.getStatus() != null){
            wrapper.eq("status",orderForm.getStatus());
        }
        if(orderForm.getStartTime() != null){
            wrapper.ge("create_time",simpleDateFormat.format(orderForm.getStartTime()));
        }
        if(orderForm.getEndTime() != null){
            wrapper.le("create_time",simpleDateFormat.format(orderForm.getEndTime()));
        }
        IPage<TbOrder> orderIPage = orderMapper.selectPage(page,wrapper);
        return orderIPage;
    }

}
